package cn.sunjinxin.trade.domain.model;

import cn.sunjinxin.savior.core.helper.SpringHelper;
import cn.sunjinxin.trade.domain.enums.TocType;
import cn.sunjinxin.trade.domain.status.TocStatus;
import lombok.Data;
import lombok.experimental.FieldDefaults;

import java.util.Date;

/**
 * @author issavior
 */
@Data
@FieldDefaults(level = lombok.AccessLevel.PRIVATE)
public class Toc {

    Long taskId;

    Order order;

    String request;

    TocType tocType;

    TocStatus status;

    Long executeTime;

    Date createTime;

    Date updateTime;

    public static Toc init(Order order, TocType tocType) {
        Toc toc = new Toc();
        toc.status = TocStatus.INIT;
        toc.order = order;
        toc.tocType = tocType;
        toc.executeTime = order.getProductSpu().getPreorderTimeOut();
        return toc;
    }

    public void register() {
        // 异步注册，不阻塞主链路
        Object bean = SpringHelper.getBean(Object.class);
        int i = bean.hashCode();
        System.out.println("注册超时任务" + i);
    }


}
